<section class="address-overview" data-page="address-details" data-page-address-hash="<%= @address.hash %>">
  <div class="row">
    <!-- Address details -->
    <div class="card-section col-md-12 col-lg-8 pr-0-md">
      <div class="card">
        <div class="card-body">
          <h1 class="card-title lg-card-title">
            <%= address_title(@address) %> <%= gettext "Details" %>
            <!-- buttons -->
            <span class="overview-title-buttons float-right">
              <span class="overview-title-item" data-clipboard-text="<%= @address %>">
                <span
                  aria-label='<%= gettext("Copy Address") %>'
                  class="btn-copy-icon"
                  data-placement="top"
                  data-toggle="tooltip"
                  title='<%= gettext("Copy Address") %>'
                >
                  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32.5 32.5" width="32" height="32">
                    <path fill-rule="evenodd" d="M23.5 20.5a1 1 0 0 1-1-1v-9h-9a1 1 0 0 1 0-2h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1zm-3-7v10a1 1 0 0 1-1 1h-10a1 1 0 0 1-1-1v-10a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1zm-2 1h-8v8h8v-8z"/>
                  </svg>
                </span>
              </span>
              <span
                class="overview-title-item"
                data-target="#qrModal"
                data-toggle="modal"
              >
                <span
                  class="btn-qr-icon"
                  data-toggle="tooltip"
                  data-placement="top"
                  title='<%= gettext("QR Code") %>'
                  aria-label='<%= gettext("Show QR Code") %>'
                >
                  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32.5 32.5" width="32" height="32">
                    <path fill-rule="evenodd" d="M22.5 24.5v-2h2v2h-2zm-1-4v-1h1v1h-1zm1-3h2v2h-2v-2zm1-2h-5a1 1 0 0 1-1-1v-5a1 1 0 0 1 1-1h5a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1zm-1-5h-3v3h3v-3zm-8 14h-5a1 1 0 0 1-1-1v-5a1 1 0 0 1 1-1h5a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1zm-1-5h-3v3h3v-3zm1-4h-5a1 1 0 0 1-1-1v-5a1 1 0 0 1 1-1h5a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1zm-1-5h-3v3h3v-3zm6 9h-2v-2h2v2zm1 1h-1v-1h1v1zm0 1v1h-1v-1h1zm-1 3h-2v-2h2v2z"/>
                  </svg>
                </span>
              </span>
              <%= if validator_metadata = primary_validator_metadata(@address) do %>
                <span
                  class="overview-title-item"
                  data-target="#validatorModal"
                  data-toggle="modal"
                >
                  <span
                    aria-label='<%= gettext("Show Validator Info") %>'
                    class="btn-address-card-icon"
                    data-placement="top"
                    data-toggle="tooltip"
                    title='<%= gettext("Validator Info") %>'
                  >
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="10">
                      <path fill-rule="evenodd" d="M19 6h-6a1 1 0 0 1 0-2h6a1 1 0 0 1 0 2zm0-4h-6a1 1 0 0 1 0-2h6a1 1 0 0 1 0 2zM9 10H1a1 1 0 0 1-1-1V7a2 2 0 0 1 2-2h.184A2.962 2.962 0 0 1 2 4V3a3 3 0 1 1 6 0v1c0 .353-.072.686-.184 1H8a2 2 0 0 1 2 2v2a1 1 0 0 1-1 1zM6 3a1 1 0 0 0-2 0v1a1 1 0 0 0 2 0V3zm2 4H2v1h6V7zm5 1h6a1 1 0 0 1 0 2h-6a1 1 0 0 1 0-2z"/>
                    </svg>
                  </span>
                </span>
              <% end %>
            </span>
          </h1>
          <h3 class="address-detail-hash-title <%= if BlockScoutWeb.AddressView.contract?(@address) do %>contract-address<% end %>" data-test="address_detail_hash"><%= @address %></h3>
          <div class="d-flex flex-column flex-lg-row justify-content-start text-muted">
            <%= if address_name = primary_name(@address) do %>
              <strong class="mr-4 mb-2 text-dark"><%= address_name %></strong>
            <% end %>
            <%= if @address.token do %>
              <span class="mr-4 mb-2">
                <%= link(token_title(@address.token), to: token_path(@conn, :show, @address.hash), "data-test": "token_hash_link" ) %>
              </span>
            <% end %>
            <span>
              <span class="address-detail-item">
                <%= if contract?(@address) do %>
                  <%= gettext(">=") %>
                  <span data-selector="transaction-count">
                    <%= incoming_transaction_count(@address.hash) %>
                  </span>
                  <%= gettext("Incoming Transactions") %>
                <% else %>
                  <span data-selector="transaction-count">
                    <%= BlockScoutWeb.Cldr.Number.to_string!(@transaction_count, format: "#,###") %>
                  </span>
                  <%= gettext("Transactions Sent") %>
                <% end %>
              </span>
              <%= if @address.fetched_coin_balance_block_number do %>
                <span class="address-detail-item">
                  <%= gettext("Last Balance Update: Block #") %><span data-selector="fetched-coin-balance-block-number"><%= @address.fetched_coin_balance_block_number %></span>
                </span>
              <% end %>
              <%= if validator?(@validation_count) do %>
                <span class="address-detail-item">
                  <span data-selector="validation-count">
                    <%= BlockScoutWeb.Cldr.Number.to_string!(@validation_count, format: "#,###") %>
                  </span>
                  <%= gettext("Blocks Validated") %>
                </span>
              <% end %>
            </span>
          </div>
          <% from_address_hash = from_address_hash(@address) %>

          <%= if contract?(@address) do %>
            <span class="text-muted" data-test="address_contract_creator">
              <%= if from_address_hash do %>
                <%= gettext "Created by" %> <%= link(
                  trimmed_hash(from_address_hash(@address)),
                  to: address_path(@conn, :show, from_address_hash(@address))
                ) %>

                <%= gettext "at" %>

                <%= link(
                  trimmed_hash(transaction_hash(@address)),
                  to: transaction_path(@conn, :show, transaction_hash(@address)),
                  "data-test": "transaction_hash_link"
                ) %>
              <% else %>
                <p class="alert alert-danger" role="alert"><%= gettext("Error: Could not determine contract creator.") %></p>
              <% end %>
            </span>
          <% end %>
          <!-- Verify in other explorers -->
          <!--
          <%# <%= render "_verify_other_explorers.html", hash: @address.hash, type: "address" %> %>
          -->
        </div>
      </div>
    </div>
    <!-- Balance -->
    <div class="card-section col-md-12 col-lg-4 pl-0-md" data-selector="balance-card">
      <%= render BlockScoutWeb.AddressView, "_balance_card.html", conn: @conn, address: @address, exchange_rate: @exchange_rate, coin_balance_status: @coin_balance_status %>
    </div>

  </div>
</section>

<!-- Modal QR -->
<div class="modal fade" id="qrModal" tabindex="-1" role="dialog" aria-labelledby="qrModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title" id="qrModalLabel"><%= gettext "QR Code" %></h2>
        <button type="button" class="close" data-dismiss="modal" aria-label="<%= gettext("Close") %>">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <img src="data:image/png;base64, <%= qr_code(@address.hash) %>" class="qr-code" alt="qr_code" title="<%= @address %>" />
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" data-dismiss="modal"><%= gettext "Close" %></button>
      </div>
    </div>
  </div>
</div>

<!-- Modal Validator -->
<%= if validator_metadata do %>
  <%= render BlockScoutWeb.AddressView, "_validator_metadata_modal.html", address_name: address_name, validator_metadata: validator_metadata %>
<% end %>
